<?php

class Guest extends CI_Controller {

    function __construct() {
        parent::__construct();
        $level_id = $this->session->userdata('logged_in');
        if ($level_id['level_id'] == null) {
            redirect('user/login', 'refresh');
        }
        if ($level_id['level_id'] == 0) {
            redirect('user', 'refresh');
        }
    }

    function index() {

        $crud = new grocery_CRUD();

        $crud->set_table('guest');
        $crud->set_subject('Guest');
        $crud->required_fields('guest_name', 'guest_address', 'guest_phone', 'guest_group','Desc');
        $crud->columns('guest_name', 'guest_ktp', 'guest_address', 'guest_phone', 'guest_group','Desc');
        $crud->order_by('guest_id', 'desc');

        $crud->display_as('guest_name', 'Name');
        $crud->display_as('guest_ktp', 'ID Card');
        $crud->display_as('guest_address', 'Address');
        $crud->display_as('guest_phone', 'Phone');
        $crud->display_as('guest_group', 'Guest Type');
		$crud->display_as('Desc', 'Description');

        $crud->callback_field('guest_ktp', array($this, 'KTP_desc'));

        $output = (array) $crud->render();
        $output['title'] = 'Guest List';

        $this->load->template('guest/index', $output);
    }

    function KTP_desc($value = '') {
        return '<input type="number" maxlength="16" value="' . $value . '" name="guest_ktp" style="width:auto">';
    }

}
